package ioperations;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        int currentSize = bookList.getUsedSize();
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the name of the book: ");
        String bookName = sc.nextLine();

        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if (bookList.getBook(i).getName().equals(bookName)) {
                if(book.isBorrowed()){
                    System.out.println("书已被借出");
                    return;
                }

                book.setBorrowed(true);
                System.out.println("借阅成功");
                return;
            }
        }

        System.out.println("没这本书");


    }
}
